const connections = require("../app/database");

class OrderService {
  async getProfitService() {
    const statement = `SELECT o.old_price,o.order_price,g.goods_name
	from sp_order o
	LEFT JOIN sp_goods_copy1 g
	on o.goods_id = g.goods_id;`;
    const res = connections.execute(statement);
    return res;
  }

  async getbaseService(id) {
    // console.log(id);
    const statement = `select o.order_id,o.order_number,b.*
  from sp_order o
  left JOIN base b
  on o.base_id = b.base_id
  where o.order_id =?;`;
    console.log(1);
    const res = connections.execute(statement, [+id]);
    return res;
  }

  async getOrderService() {
    console.log(1);
    const statement = `SELECT o.*,g.goods_name
        from sp_order o
        LEFT JOIN sp_goods_copy1 g
        on o.goods_id = g.goods_id;`;
    const res = await connections.execute(statement);
    return res[0];
  }

  async getSortService() {
    const statement = `SELECT count(*) value,g.goods_name name from
    sp_order o
    LEFT JOIN sp_goods_copy1  g
    on o.goods_id = g.goods_id
    GROUP BY o.goods_id;`;
    const res = await connections.execute(statement);
    return res[0];
  }
}
module.exports = new OrderService();
